package com.atguigu.yygh.common.result;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author luoyin
 * @Date 21:10 2022/9/19
 **/
@Getter
public class R {
    private Integer code ;
    private Boolean success;
    private String message;
    private Map<String,Object> data = new HashMap<>();

    private R(){};

    public static R ok(){
        R r = new R();
        r.code = REnum.OK.getCode();
        r.message = REnum.OK.getMessage();
        r.success = REnum.OK.getSuccess();
        return r;
    }

    public static R error(){
        R r = new R();
        r.code = REnum.ERROR.getCode();
        r.message = REnum.ERROR.getMessage();
        r.success = REnum.ERROR.getSuccess();
        return r;
    }

    public R message(String message){
        this.message = message;
        return this;
    }
    public R code(Integer code){
        this.code = code;
        return this;
    }
    public R data(Map<String,Object> data){
        this.data = data;
        return this;
    }
    public R data(String key , Object value){
        this.data.put(key,value);
        return this;
    }

}
